﻿namespace Web.Control.Member.Public
{
    using System;
    using System.Data;
    using System.Drawing;
    using System.Web;
    using System.Web.Security;
    using System.Web.UI.WebControls;
    using System.Web.UI.HtmlControls;    
    using System.Collections;
    using Lx.Web.Common.UI;
    using Lx.Web.Common.ControlsUI;
    using Model.WWW_User.User;

    public class SBlackboard : BaseControl
    {
        /// <summary>
        /// 当前用户与该会员关系1好友，2已是联系人，0无int、
        /// </summary>
        protected int UserRelation = -1;
        /// <summary>
        /// 查看会员信息
        /// </summary>
        protected UserProfileModel userInfo;        
        /// <summary>
        /// 当前用户编号
        /// </summary>
        protected string mymemberno = "";
        //小黑板
        protected Repeater rptComment;
        /// <summary>
        /// 小黑板信息数量
        /// </summary>
        protected int RecordCount = 0;
        protected int PageIndex = 1;        
        protected Literal litCount;
        protected int PageSize = 15;
        /// <summary>
        /// 是否有权限查看1有、0无
        /// </summary>
        protected int IsView = 0;
        /// <summary>
        /// 是否有权限留言1有、0无
        /// </summary>
        protected int IsAddComment = 0;

        protected override void OnLoad(EventArgs e)
        {
            mymemberno = HttpContext.Current.User.Identity.Name;
            if (string.IsNullOrEmpty(Request["MNo"]))
            {
                Response.End();
                return;
            }
            string memberno = Request["MNo"];
            //if (!string.IsNullOrEmpty(Request["p"]))
            //{
            //    if (Request["p"] == "L")
            //    {
            //        PageIndex = 999;
            //    }
            //    else
            //    {
            //        int.TryParse(Request["p"], out PageIndex);
            //        if (PageIndex == 0)
            //        {
            //            PageIndex = 1;
            //        }
            //    }
            //}
            if (litCount != null) int.TryParse(litCount.Text, out PageSize);
            ArrayList arrList = BLF.WWW_User.Users.User.GetUserPComment(memberno, mymemberno, PageIndex, PageSize);
            if (arrList != null)
            {
                UserRelation = (int)arrList[0];
                userInfo = arrList[1] as UserProfileModel;
                IsView = (int)arrList[2];
                string addComment = (string)arrList[3];                
                if (addComment == "3" || (addComment == "2" && UserRelation != 1) || (addComment == "1" && mymemberno == ""))
                {
                    IsAddComment = 0;
                }
                else {
                    IsAddComment = 1;
                }
                if (IsView == 1)
                {
                    if (rptComment != null)
                    {
                        rptComment.DataSource = arrList[4];
                        rptComment.DataBind();
                    }
                    RecordCount = (int)arrList[5];
                }
                Response.Write("<script> var comPage=" + (new System.Web.Script.Serialization.JavaScriptSerializer()).Serialize(new BLF.PageableObject(RecordCount, PageIndex, PageSize)) + ";</script>");
                //title
                this.DynamicTitle = GetText("Comments on {0}'s blackboard - italki", new string[] { userInfo.Nickname });
                this.DynamicKeywords = GetText("{0}, blackboard, comment", new string[] { userInfo.Nickname });
                this.DynamicDescription = GetText("Comments on {0}'s blackboard italki", new string[] { userInfo.Nickname });
            }
            else
            {
                Response.End();
                return;
            }
        }
    }
}

